package com.magpiebridge.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.magpiebridge.dao.ManagerDao;
import com.magpiebridge.pojo.Manager;
import com.magpiebridge.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManagerServiceImpl implements ManagerService {

    @Autowired
    private ManagerDao managerDao;
    @Override
    public int insertManager(Manager manager) {
        return managerDao.insertManager(manager);
    }

    @Override
    public int deleteManager(Integer id) {
        return managerDao.deleteById(id);
    }

    @Override
    public int updateManager(Manager manager) {
        return managerDao.updateById(manager);
    }

    @Override
    public List<Manager> getAllManager() {
        return managerDao.selectList(null);
    }

    @Override
    public Manager getManagerById(Integer id) {
        return managerDao.selectById(id);
    }

    @Override
    public  boolean  login(Manager  manager)  {
        QueryWrapper<Manager>  queryWrapper  =  new  QueryWrapper<>();
        queryWrapper.eq("admin",  manager.getAdmin());
        Manager  dbManager  =  managerDao.selectOne(queryWrapper);
        if  (dbManager  !=  null  &&  managerDao.validatePassword(dbManager,  manager.getPassword()))  {
            return  true;
        }
        return  false;
    }
}
